package com.lanou3g.bbs.service;

import com.lanou3g.bbs.dao.Dao;
import com.lanou3g.bbs.entity.User;
import com.lanou3g.bbs.util.JDBCUtil;
import org.springframework.beans.factory.annotation.Autowired;

@org.springframework.stereotype.Service
public class Service {
    @Autowired
    private Dao dao;

    public User login(User user) {
        try {
            JDBCUtil.begin();
            if (user.getName() == null || user.getPwd() == null) {
                return null;
            }
            if (!dao.loginDao(user)) {
                return null;
            }
        } finally {
            JDBCUtil.closeConn();
        }
        return user;
    }

    public boolean register(User user) {
        JDBCUtil.begin();
        if (!dao.hasThisName(user)) {
            JDBCUtil.closeConn();
            return dao.register(user);
        }
        return false;
    }
}
